package com.apes.framework.config.dozer;

import com.apes.framework.util.DateUtil;
import org.dozer.DozerConverter;

import java.util.Date;

/**
 * 功能：
 *
 * @author xul
 * @create 2018-07-10 8:55
 */
public class DateDozerConverter extends DozerConverter<String, Date> {

    public DateDozerConverter() {
        super(String.class, Date.class);
    }

    @Override
    public Date convertTo(String source, Date destination) {
        if ( source == null )  return null;
        if (source.length() == 0) {
            return null;
        } else {
            if (source.length() < 11) {
                return DateUtil.parse(source);
            } else {
                return DateUtil.parseTimestamp(source);
            }
        }
    }

    @Override
    public String convertFrom(Date source, String destination) {
        throw new IllegalStateException("Unknown value!");
    }
}